<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电话号码升位</title>
</head>
<body>

    <h2>电话号码升位程序</h2>
    <label for="phone">请输入电话号码（例如：0871-1234567）：</label>
    <input type="text" id="phone" placeholder="请输入电话号码" />
    <button onclick="upgradePhone()">升位</button>

    <p id="result"></p>

    <script>
        function upgradePhone() {
            var phone = document.getElementById('phone').value;
            var regex = /^(\d{3,4})-(\d{7,8})$/;  // 匹配区号和电话号码
            var result = document.getElementById('result');
            
            // 如果电话号码符合规则
            if (regex.test(phone)) {
                var matches = phone.match(regex);
                var areaCode = matches[1];  // 区号
                var number = matches[2];    // 电话号码

                // 升位处理：最高位+1，前补6
                var upgradedNumber = areaCode + '-6' + number;
                result.textContent = '升位后的电话号码：' + upgradedNumber;
            } else {
                result.textContent = '请输入有效的电话号码（格式：区号-电话号码）。';
            }
        }
    </script>

</body>
</html>
